package com.gdust.lease.common.exception;

import com.gdust.lease.common.result.ResultCodeEnum;
import lombok.Data;

/**
 * ClassName: LeaseException
 * Package: com.gdust.lease.common.exception
 * Description:自定义异常对象LeaseException
 *
 * @Author syun
 * @Create 2025/1/3 19:09
 * @Version 1.0
 */
@Data
public class LeaseException extends RuntimeException{
    //自定义状态码
    private Integer code;

    /**
     * 通过状态码和错误消息创建异常对象
     * @param code 状态码
     * @param message 错误消息
     */
    public LeaseException(Integer code,String message){
        //message属性调用父类构造器进行设置
        super(message);
        this.code = code;
    }

    /**
     * 根据响应结果枚举对象创建异常对象
     * @param resultCodeEnum 响应结果枚举对象
     */
    public LeaseException(ResultCodeEnum resultCodeEnum) {
        //调用父类构造器RuntimeException获取message属性
        super(resultCodeEnum.getMessage());
        this.code = resultCodeEnum.getCode();
    }

    @Override
    public String toString() {
        return "LeaseException{" +
                "code=" + code +
                ", message=" + this.getMessage() +
                '}';
    }

}
